11110 - Equidivisions (DFS, maratón colombiana) &&
[and.git] / 11067 - Little red riding hood / 11067.cpp
blob988eb35a715081f3e22456043223a7617db25e7f
1 #include <iostream>
3 using namespace std;
5 unsigned int dp[101][101];
6 bool wolf[101][101];
9 int main(){
10 int w, h;
11 while (cin >> w >> h && w && h){
12 for (int i=0; i<=w; ++i){
13 for (int j=0; j<=h; ++j){
14 dp[i][j] = wolf[i][j] = 0;
17 int wolves;
18 cin >> wolves;
19 while (wolves--){
20 int i, j;
21 cin >> i >> j;
22 wolf[i][j] = true;
25 dp[0][0] = 1;
26 for (int i=0; i<=w; ++i){
27 for (int j=0; j<=h; ++j){
28 if (!wolf[i][j]){
29 if (i > 0) dp[i][j] += dp[i-1][j];
30 if (j > 0) dp[i][j] += dp[i][j-1];
35 int t = dp[w][h];
36 if (t == 0){
37 cout << "There is no path." << endl;
38 }else{
39 cout << "There ";
40 if (t == 1) cout << "is one path";
41 else cout << "are " << t << " paths";
42 cout << " from Little Red Riding Hood's house to her grandmother's house." << endl;
46 return 0;